package br.com.fiap.trabalho.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

@Entity
public class Movie {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)  //Sera usado auto increment.
	@Column(name="id_movie")
	private Integer id;
	private String title;
	@Column(name="ano", nullable=true)
	private int year;
	@ManyToMany
	@JoinTable(name="Movie_Actor", 
		joinColumns=@JoinColumn(name="id_movie"), 
		inverseJoinColumns=@JoinColumn(name="id_actor"))
	private List<Actor> actor = new ArrayList<Actor>();
	@ManyToOne
	@JoinColumn(name = "id_studio")
	private Studio studio;
	@ManyToMany
	@JoinTable(name="Movie_Category", 
		joinColumns=@JoinColumn(name="id_movie"), 
		inverseJoinColumns=@JoinColumn(name="id_category"))
	private List<Category> category = new ArrayList<Category>();
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public List<Actor> getActor() {
		return actor;
	}
	public void setActor(List<Actor> actor) {
		this.actor = actor;
	}
	public Studio getStudio() {
		return studio;
	}
	public void setStudio(Studio studio) {
		this.studio = studio;
	}
	public List<Category> getCategory() {
		return category;
	}
	public void setCategory(List<Category> category) {
		this.category = category;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj){
			return true;
		}
		if (obj == null){
			return false;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		Movie other = (Movie) obj;
		if (id != other.id){
			return false;
		}
		return true;
	}
	
	
}